/**
 * Created by Administrator on 2017/3/2 0002.
 */
var Page9={
    create:function () {
    var page={};

        var t0,t1,t2,t3,t4,i0;
        var tw_whole,tw_t0,tw_t1,tw_t2,tw_t3,tw_t4,tw_t5,tw_logo,tw_i0,tw_click;
        page.ui=new PIXI.DisplayObjectContainer();

        var bg=new PIXI.Sprite(resource['assets/images/p9_bg.png'].texture);
        page.ui.addChild(bg);

        var t0=new PIXI.Sprite(resource['assets/images/p9_t0.png'].texture);
        t0.x=370;
        t0.y=172;
        t0.alpha=0;
        t0.anchor.set(0.5);
        page.ui.addChild(t0);

        var i0=new PIXI.Sprite(resource['assets/images/p9_img0.png'].texture);
        i0.x=370;
        i0.y=508;
        i0.alpha=0;
        i0.anchor.set(0.5);
        page.ui.addChild(i0);

        var t1=new PIXI.Sprite(resource['assets/images/p9_t1.png'].texture);
        t1.x=373;
        t1.y=796;
        t1.alpha=0;
        t1.anchor.set(0.5);
        page.ui.addChild(t1);

        var t2=new PIXI.Sprite(resource['assets/images/p9_t2.png'].texture);
        t2.x=370;
        t2.y=852;
        t2.alpha=0;
        t2.anchor.set(0.5);
        page.ui.addChild(t2);

        var t3=new PIXI.Sprite(resource['assets/images/p9_t3.png'].texture);
        t3.x=370;
        t3.y=928;
        t3.alpha=0;
        t3.anchor.set(0.5);
        page.ui.addChild(t3);

        var t4=new PIXI.Sprite(resource['assets/images/p9_t4.png'].texture);
        t4.x=373;
        t4.y=988;
        t4.alpha=0;
        t4.anchor.set(0.5);
        page.ui.addChild(t4);

        var t5=new PIXI.Sprite(resource['assets/images/p9_t5.png'].texture);
        t5.x=371;
        t5.y=1029;
        t5.alpha=0;
        t5.anchor.set(0.5);
        page.ui.addChild(t5);

        var logo=new PIXI.Sprite(resource['assets/images/p9_logo.png'].texture);
        logo.x=712;
        logo.y=967;
        logo.alpha=0;
        logo.anchor.set(0.5);
        page.ui.addChild(logo);



        page.In=function () {
            if(tw_whole)
            {
                tw_whole.stop();
                TWEEN.remove(tw_whole);
            }

            tw_t0=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(1500+100)
                .onUpdate(function () {
                    t0.alpha=this.alpha;
                    t0.scale.x=this.scale;
                    t0.scale.y=this.scale;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();

            tw_i0=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(1500+400)
                .onUpdate(function () {
                    i0.alpha=this.alpha;
                    i0.scale.x=this.scale;
                    i0.scale.y=this.scale;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();

            tw_t1=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(1500+700)
                .onUpdate(function () {
                    t1.alpha=this.alpha;
                    t1.scale.x=this.scale;
                    t1.scale.y=this.scale;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();
            tw_t2=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(1500+1000)
                .onUpdate(function () {
                    t2.alpha=this.alpha;
                    t2.scale.x=this.scale;
                    t2.scale.y=this.scale;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();
            tw_t3=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(1500+1300)
                .onUpdate(function () {
                    t3.alpha=this.alpha;
                    t3.scale.x=this.scale;
                    t3.scale.y=this.scale;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();
            tw_t4=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(1500+1700)
                .onUpdate(function () {
                    t4.alpha=this.alpha;
                    t4.scale.x=this.scale;
                    t4.scale.y=this.scale;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();
            tw_t5=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(1500+2000)
                .onUpdate(function () {
                    t5.alpha=this.alpha;
                    t5.scale.x=this.scale;
                    t5.scale.y=this.scale;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();

            tw_logo=new TWEEN.Tween({x:712+150,alpha:0})
                .to({x:712,alpha:1},1000)
                .delay(1500+2300)
                .onUpdate(function () {
                    logo.alpha=this.alpha;
                    logo.x=this.x;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();
        }
        page.Out=function () {
            if(tw_t0)
            {
                tw_t0.stop();
            }
            if(tw_t1)
            {
                tw_t1.stop();
            }


            tw_whole=new TWEEN.Tween({alpha:1})
                .to({alpha:0},400)
                .onUpdate(function () {
                    page.ui.alpha=this.alpha;
                })
                .onComplete(function () {
                    page.ui.alpha=1;
                    t0.alpha=0;
                    t1.alpha=0;
                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();
        }

        var downPT={x:0,y:0};
        function upHandler(e) {
            var dis=(e.data.global.x-downPT.x)*(e.data.global.x-downPT.x)-(e.data.global.y-downPT.y)*(e.data.global.y-downPT.y)
            if(dis<25)
            {
                console.log('click');
                t2.interactive=false;
                pageOut();
            }
        }
        function downHandler(e) {
            downPT.x=e.data.global.x;
            downPT.y=e.data.global.y;
        }
        function pageOut()
        {
            if(tw_click)
            {
                tw_click.stop();
            }
            var event = new CustomEvent("Game_PageOut", {detail:8});
            var event = new CustomEvent("Game_PageIn", {detail:9});
            document.dispatchEvent(event);
            new TWEEN.Tween({scale:1,x:0,y:0,alpha:1})
                .to({scale:10,x:-1562,y:-1156,alpha:0},3000)
                .onUpdate(function () {
                    page.ui.alpha=this.alpha;
                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();
        }

    return page;
    }
}